package mms.farina.thecell;


import java.util.ArrayList;
import java.util.Calendar;

import mms.farina.thecell.activities.ChatMain;
import mms.farina.thecell.activities.MainActivity;
import mms.farina.thecell.activities.SendMessage;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

/**Classe per la gestione delle notifiche persistenti e non persistenti*/
public class Notifier{

	private  int MOOD_SERVICE_ACTIVE = R.layout.n1;
	private  int notifId = 0;
	private  NotificationManager mNM;
	private  ArrayList<Integer> notiList;
	private  Context context;
	
	
	

	public Notifier(Context context){
		this.context=context;
		notiList=new ArrayList<Integer>();
		mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
	}
	
	public void showNotificationMessage(int icon, String text, String type, String alias) {
		
		ChatMain.selectedAlias=alias;
		PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
				new Intent(context, SendMessage.class), 0);
		
		Notification notif = ( new Notification.Builder(context)
		.setContentTitle(type)
		.setContentText(text)
		.setTicker(text)
		.setSound(null)
		.setSmallIcon(icon)
		.setContentIntent(contentIntent)
		.setWhen(Calendar.getInstance().getTimeInMillis())).getNotification();

		notiList.add(notifId);
		mNM.notify(notifId++, notif);
	}

	public void showNotificationAlert(int icon, String text, String type) {
		
		
		Notification notif = ( new Notification.Builder(context)
		.setContentTitle(type)
		.setContentText(text)
		.setTicker(text)
		.setSound(null)
		.setSmallIcon(icon)
		.setWhen(Calendar.getInstance().getTimeInMillis())).getNotification();

		notiList.add(notifId);
		mNM.notify(notifId++, notif);
	}



	public void mainNotification() {

		PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
				new Intent(context, MainActivity.class), 0);

		Notification notif = (new Notification.Builder(context)
		.setContentTitle("TheCell")
		.setContentText("TheCell is running")
		.setSmallIcon(R.drawable.piratebrivescharensac)
		.setOngoing(true)
		.setContentIntent(contentIntent)) // cannot be cancelled by user but only by app
		.getNotification();
		mNM.notify(MOOD_SERVICE_ACTIVE, notif);

	}
	
	public void mainNotificationNoIntent() {

		Notification notif = (new Notification.Builder(context)
		.setContentTitle("TheCell")
		.setContentText("TheCell is running")
		.setSmallIcon(R.drawable.piratebrivescharensac)
		.setOngoing(true))// cannot be cancelled by user but only by app
		.getNotification();
		mNM.notify(MOOD_SERVICE_ACTIVE, notif);

	}
	
	public void destroyNotify(int id){
		mNM.cancel(id);
	}
	
	public void destroyAllNotify(){
		for(int id: notiList)mNM.cancel(id);
		
	}
	
	public void destroyMainNotify(){
		mNM.cancel(MOOD_SERVICE_ACTIVE);
	}
	


}
